package com.ruoyi.app.controller;

import com.ruoyi.app.utils.AjaxResult;
import com.ruoyi.app.service.IAppUserLoginService;
import com.ruoyi.web.wuliu.domain.AppUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * 【请填写功能名称】Controller
 *
 * @author zfan
 * @date 2021-05-27
 */
@Api(tags = "小程序端-登录控制器")
@RestController
@RequestMapping
public class AppUserLoginController {

    @Autowired
    private IAppUserLoginService loginService;

    @ApiOperation("小程序微信授权登录入口")
    @PostMapping("/app/login")
    public AjaxResult<AppUser> appLogin(@RequestParam String code, @RequestParam String rawData,
                                        @RequestParam String encryptedData, @RequestParam String iv) {
        return loginService.appLogin(code, rawData, encryptedData, iv);
    }

    @ApiOperation("小程序退出登录")
    @DeleteMapping("/app/loginOut")
    public AjaxResult<String> apploginOut(HttpServletRequest request) {
        return loginService.apploginOut(request);
    }

    @ApiOperation("不要调用此接口，后台开发人员测试登录小程序")
    @PostMapping("/app/login/dev")
    public AjaxResult<AppUser> login(@RequestParam String telephone) {
        String openId = "123456789";
        return loginService.devLogin(openId, telephone);
    }

    @ApiOperation("获取用户信息")
    @PostMapping("/app/getUser")
    public AjaxResult<AppUser> getUser(HttpServletRequest request) {
        return loginService.getUser(request);
    }

}
